<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增施工资料')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-impl-add"  th:object="${pId}">
            <div class="form-group" hidden>
                <div class="col-sm-8" >
                    <input name="pId" class="form-control" th:value="${pId}">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">资料类型：</label>
                <div class="col-sm-8">
                    <select id="imType" name="imType" th:with="type=${@dict.getType('sys_impl_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">资料名称：</label>
                <div class="col-sm-8">
                    <input id="imName" name="imName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">上传资料：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="imData" class="form-control" type="file" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="imRemark" name="imRemark" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label" hidden>项目信息：</label>
                <div class="col-sm-8">
                    <input id="imPro" name="imPro" class="form-control" type="hidden" th:value="${pId}">
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">审批状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <select id="imState" name="imState" th:with="type=${@dict.getType('impl_approval')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}">
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label">审批意见：</label>
                <div class="col-sm-8">
                    <input id="imOpinion" name="imOpinion" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "ruoyi/impl"
        $("#form-impl-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('imType', $("#imType").val());
            formData.append('imName', $("#imName").val());
            formData.append('imTime', $("#imTime").val());
            formData.append('imTheHeir', $("#imTheHeir").val());
            formData.append('imRemark', $("#imRemark").val());
            formData.append('imPro', $("#imPro").val());
            formData.append('imState', $("#imState").val());
            formData.append('imOpinion',$("#imOpinion").val());
            formData.append('file', $('#filePath')[0].files[0]);
            $.ajax({
                url: prefix + "/add/",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }

        $("input[name='imTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>